from django.shortcuts import render
from django.core.paginator import Paginator
#引入对应的数据库对象类
# from foodCook.models import FoodCook
# from django.db.models import Max
#引入JsonResponse模块
from django.http import JsonResponse
#导入json模块
import json
#导入uuid模块
import uuid
#导入哈希模块
import hashlib
import os
from django.conf import settings

from CommScripts.bdMap import baiduSearchBase
# 解除clickjacking防御
from django.views.decorators.clickjacking import xframe_options_exempt

import requests







@xframe_options_exempt
def baiduSearchData(request):
    # 接受查询条件，并将接收数据解析为json
    # print(request.body)
    data = json.loads(request.body.decode('utf-8'))
    # print(data)
    # return JsonResponse({'code': 1, 'data': data})
    try:
        # response = requests.get(url="https://api.map.baidu.com/place/v2/suggestion", params=data)
        # if response:
            # reData=response.json()
        reData= baiduSearchBase(data)
        # reData = reData.json()
        if reData["status"]==0:
            reData1=reData["result"]
            return JsonResponse({'code': 1, 'data': reData1})
        else:
            return JsonResponse({'code':0,'msg':reData["message"]})
    except Exception as e:
        return JsonResponse({'code': 0, 'msg': e})
